require(['jquery', 'cookie', 'app', 'lay', 'base64'], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                that: []
            }
            , created: function () {
                this.that = playGet("v1/api/swiper/List/PAY").data
            }
            , methods: {
                referXadmin: function () {
                    window.reload();
                },
                deleted: function (uuid) {
                    var re = playDelete("v1/api/swiper/" + uuid);
                    this.referXadmin();
                },
                add: function () {
                    var ck = getCode("2");
                    $(".layui-table").append("<tr><td><a style=\"color: #0000FF\" target=\"_blank\"></a></td><td ondblclick=\"editDBL(this)\"></td>" +
                        "<td><div class=\"layui-btn-group\">\n" +
                        "                        <button class=\"layui-btn layui-btn-radius layui-btn-warm\" id='" + ck + "' >上传</button>\n" +
                        /*
                                                "                        <button class=\"layui-btn layui-btn-radius layui-btn-danger\" @click=\"deleted(item.id)\">删除</button>\n" +
                        */
                        "                    </div></td></tr>");
                    layui.use('upload', function () {
                        var upload = layui.upload;
                        //执行实例
                        var uid = "#" + ck;
                        upload.render({
                            elem: uid //绑定元素
                            , url: configPro.server_img_interface //上传接口
                            , done: function (res) {
                                $(uid).parent().parent().prev().prev().find("a").text(res.data.data.src);
                                var keyst = $(uid).parent().parent().prev().text();
                                if (keyst.trim() == "") {
                                    alr("请先设置排序");
                                    return false;
                                }
                                var re = playPost("v1/api/swiper/Save", "", JSON.stringify({
                                    val: res.data.data.src,
                                    keyst: getCode(8),
                                    val2: keyst,
                                    type: "PAY",
                                }));
                                alr(re.msg);
                                this.referXadmin();
                            }
                            , error: function (res) {
                                alr("上传失败");
                            }
                        });
                    });
                }
            }
        });

        layui.use('upload', function () {
            var upload = layui.upload;
            //执行实例
            for (var i = 0; i < dic.that.length; i++) {
                (function (j) {
                    var uid = "#" + dic.that[j]['id'];
                    upload.render({
                        elem: "#" + dic.that[j]['id'] //绑定元素
                        , url: configPro.server_img_interface //上传接口
                        , done: function (res) {
                            $(uid).parent().parent().prev().prev().find("a").attr("href", res.data.src);
                            $(uid).parent().parent().prev().prev().find("a").text(res.data.src);
                            var uuid = $(uid).attr("id");
                            var re = playPost("v1/api/swiper/Save", "", JSON.stringify({
                                uuid: uuid,
                                val: res.data.src
                            }));
                            alr(re.msg);
                        }
                        , error: function (res) {
                            alr("上传失败");
                        }
                    });
                })(i)
            }
        });

    });
});

function editDBL(e) {
    $(e).html("<input class='layui-input' type='number' onblur='editBlur(this)'/>");
}